<?php
	namespace ampleharvest\webpages\rest\admin;

	use\ampleharvest\cConfig;
	use\ampleharvest\cServers;
	use\ampleharvest\permissions;
	use\ampleharvest\code\cRestConnector;

	require_once dirname(dirname(dirname(dirname(__FILE__)))) . "/config/cConfig.php";
	$webConfig = new \ampleharvest\cConfig();
	require_once dirname(dirname(dirname(dirname(__FILE__)))) . '/config/cServers.php';
	
	require_once $webConfig->C_STR_AMPLEHARVEST_CODE . "/classes/User_Manager/cUserValidation.php";
	require_once $webConfig->C_STR_AMPLEHARVEST_CODE . "/config/cPermissions.php";
	require_once $webConfig->C_STR_AMPLEHARVEST_CODE . "/abstract_classes/abs_RestService.php";
	require_once $webConfig->C_STR_AMPLEHARVEST_CODE . '/classes/cStomp.php';
	require_once $webConfig->C_STR_AMPLEHARVEST_CODE . '/classes/cRestConnector.php';
	
	require_once $webConfig->C_STR_AMPLEHARVEST_CODE . '/classes/Tables/cTABLE_UserGroups.php';
	
	
	class rTable_UserGroups extends \rTable_Abstract
	{
		protected $m_obj_UserValidation = null;
		protected $m_obj_TABLE_UserGroups = null;
		
		const C_STR_PARAM_TYPE	= "type";
		const C_STR_PARAM_FUNCTION = "fn";
		const C_STR_PARAM_VALUE = "val";

		public function __construct()
		{
			$this->m_obj_UserValidation = new \cUserValidation();

			$this->m_obj_UserValidation->require_Login();

			$this->m_obj_TABLE_Users = new \cTABLE_Users();
			
			$this->m_obj_TABLE_UserGroups = new \cTABLE_UserGroups();

			parent::__construct();
		}

			public function output_Get_Info()
		{
			print("<h1>GET</h1>");
			print("<p>Returns the JSON data requested.</p>");
			print("<h4>Parameters</h4>");
			print("<ul>");
			print("<li>");
			print("<b>" . self::C_STR_PARAM_TYPE . "</b> - The type of request (tbl = define table, ret = grab data, q = general query");
			print("</li>");
			print("<li>");
			print("<b>" . self::C_STR_PARAM_FUNCTION . "</b> - The function to be called (Use _ for a series of actions)");
			print("</li>");
			print("<li>");
			print("<b>" . self::C_STR_PARAM_VALUE . "</b> - The value to send to the function (Use _ for a series of values)");
			print("</li>");
			print("</ul>");
		}

		public function get_Function($arr_Values)
		{
			$arr_Output = array();

			$bool_ViewStatus = $this->m_obj_UserValidation->check_Permission(permissions\cPermissions::C_STR_PERMISION_ADMIN_VIEW_STATUS);

			if (!$bool_ViewStatus)
			{
				$this->output_Error("You do not have permission to view this page.");
			}
			
			if (!isset($_REQUEST['fn']))
			{
				$this->output_Error("You must send a function as ".self::C_STR_PARAM_FUNCTION);
			}
			
			print_r(get_object_vars($this->m_obj_TABLE_UserGroups));
			exit;
				if(!method_exists($this->m_obj_TABLE_UserGroups, $_REQUEST['fn']))
				{
					//$this->output_Error(substr($_REQUEST['fn'], 0, 3));
					
					if(substr($_REQUEST['fn'], 0, 3) == 'get')
					{
						try 
						{
							eval("$this->m_obj_TABLE_UserGroups->"+$_REQUEST['fn']+"()");
						}	
						catch (Exception $e)
						{
							
						}
					}
					
					$this->output_Error($_REQUEST['fn']." is not a valid function name");
				}
				
//			}

			$this->output_Data($arr_Output);
		}


/*
		protected function check_AmpleHarvestDB()
		{
			$obj_Output = new \stdClass();
			$obj_Output->status = "UNKNOWN";

			$obj_Output->name = "AmpleHarvest DB";
			$obj_Output->date = date_format(new \DateTime(), "c");
			$obj_Output->msg = "Method has not been implemented.";
			return $obj_Output;
		}
*/
	}

	$obj_Service = new cStatus();

?>
